
//// code for immigration experiment
/// use "experimentdata.dta"



/// statistical significance and descriptives
diff expft_imm, t(rurexp) p(rural)
reg expft_imm i.kltexp##i.urb_sub_o [pweight=weight]
	margins, at(kltexp = (0 1 2 3) urb_sub_o=(0 1 2))
	marginsplot, by(urb_sub_o) recast(bar)
	
	
tabstat expft_imm if rursmall==1 & kltexp == 0
tabstat expft_imm if rursmall==1 & kltexp==1
tabstat expft_imm if rursmall==1 & kltexp==2
tabstat expft_imm if rursmall==1 & kltexp==3

tabstat expft_imm if urb_sub_o == 0 & kltexp == 0
tabstat expft_imm if urb_sub_o == 0 & kltexp==1
tabstat expft_imm if urb_sub_o == 0 & kltexp==2
tabstat expft_imm if urb_sub_o == 0 & kltexp==3

tabstat expft_imm if urb_sub_o == 1 & kltexp == 0
tabstat expft_imm if urb_sub_o == 1 & kltexp==1
tabstat expft_imm if urb_sub_o == 1 & kltexp==2
tabstat expft_imm if urb_sub_o == 1 & kltexp==3

gen econcond = .
replace econcond = 1 if kltexp == 1
replace econcond = 0 if kltexp == 0
gen respcond = .
replace respcond = 1 if kltexp == 2
replace respcond = 0 if kltexp == 0
gen mmcond = .
replace mmcond = 1 if kltexp == 3
replace mmcond = 0 if kltexp == 0

ttest expft_imm if rursmall==1, by(econcond)
ttest expft_imm if rursmall==1, by(respcond)
ttest expft_imm if rursmall==1, by(mmcond)

ttest expft_imm if urb_sub_o == 1, by(econcond)
ttest expft_imm if urb_sub_o == 1, by(respcond)
ttest expft_imm if urb_sub_o == 1, by(mmcond)

hist expft_imm, scheme(s1mono)






/////////////////////////////////////////////////////////
// FIGURE 5
////////////////////////////////////////////////////////

/// Left-hand side (all participants)

generate condimm = . 
replace condimm = 0 if urb_sub_o == 0 & kltexp==0
replace condimm = 1 if urb_sub_o == 0 & kltexp==1
replace condimm = 2 if urb_sub_o == 0 & kltexp == 2
replace condimm = 3 if urb_sub_o==0 & kltexp==3
replace condimm = 0 if urb_sub_o == 4
replace condimm = 5 if urb_sub_o == 1 & kltexp==0
replace condimm = 6 if urb_sub_o == 1 & kltexp==1
replace condimm = 7 if urb_sub_o == 1 & kltexp == 2
replace condimm = 8 if urb_sub_o==1 & kltexp==3
replace condimm = 0 if urb_sub_o == 9
replace condimm = 10 if urb_sub_o == 2 & kltexp==0
replace condimm = 11 if urb_sub_o == 2 & kltexp==1
replace condimm = 12 if urb_sub_o == 2 & kltexp == 2
replace condimm = 13 if urb_sub_o==2 & kltexp==3

graph bar (mean) expft_imm, over(kltexp) over(urb_sub_o) asyvars 


/// left-hand side of Figure 5
collapse (mean) meanimmexp= expft_imm (sd) sdftimm=expft_imm (count) n=expft_imm, by(kltexp urb_sub_o condimm)
generate hiimmft = meanimmexp + invttail(n-1,0.025)*(sdftimm/sqrt(n))
generate loimmft = meanimmexp - invttail(n-1,0.025)*(sdftimm/sqrt(n))
graph twoway (bar meanimmexp kltexp) (rcap hiimmft loimmft kltexp), by(urb_sub_o)
graph twoway (bar meanimmexp condimm if kltexp==0) (bar meanimmexp condimm if kltexp == 1) (bar meanimmexp condimm if kltexp==2) (bar meanimmexp condimm if kltexp==3) (rcap hiimmft loimmft condimm), legend (order(1 "Control" 2 "Economic Condition" 3 "Respect Condition" 4 "Majority-Minority Condition")) xlabel(0 "Urban" 6 "Suburban" 12 "Small Town/Rural", noticks) xtitle("Respondent Partisanship") ytitle("Mean Undocumented Immigrant Feeling Therm. Score") scheme(s2gcolor)


/////////// NOTE: once you have run the above, you will need to re-load the data





/// Right-hand side (white participants)
generate condimm = . 
replace condimm = 0 if urb_sub_o == 0 & kltexp==0 & white==1
replace condimm = 1 if urb_sub_o == 0 & kltexp==1 & white==1
replace condimm = 2 if urb_sub_o == 0 & kltexp == 2 & white==1
replace condimm = 3 if urb_sub_o==0 & kltexp==3 & white==1
replace condimm = 0 if urb_sub_o == 4
replace condimm = 5 if urb_sub_o == 1 & kltexp==0 & white==1
replace condimm = 6 if urb_sub_o == 1 & kltexp==1 & white==1
replace condimm = 7 if urb_sub_o == 1 & kltexp == 2 & white==1
replace condimm = 8 if urb_sub_o==1 & kltexp==3 & white==1
replace condimm = 0 if urb_sub_o == 9
replace condimm = 10 if urb_sub_o == 2 & kltexp==0 & white==1
replace condimm = 11 if urb_sub_o == 2 & kltexp==1 & white==1
replace condimm = 12 if urb_sub_o == 2 & kltexp == 2 & white==1
replace condimm = 13 if urb_sub_o==2 & kltexp==3 & white==1

graph bar (mean) expft_imm, over(kltexp) over(urb_sub_o) asyvars 


/// right-hand side of Figure 5
collapse (mean) meanimmexp= expft_imm (sd) sdftimm=expft_imm (count) n=expft_imm, by(kltexp urb_sub_o condimm)
generate hiimmft = meanimmexp + invttail(n-1,0.025)*(sdftimm/sqrt(n))
generate loimmft = meanimmexp - invttail(n-1,0.025)*(sdftimm/sqrt(n))
graph twoway (bar meanimmexp kltexp) (rcap hiimmft loimmft kltexp), by(urb_sub_o)
graph twoway (bar meanimmexp condimm if kltexp==0) (bar meanimmexp condimm if kltexp == 1) (bar meanimmexp condimm if kltexp==2) (bar meanimmexp condimm if kltexp==3) (rcap hiimmft loimmft condimm), legend (order(1 "Control" 2 "Economic Condition" 3 "Respect Condition" 4 "Majority-Minority Condition")) xlabel(0 "Urban" 6 "Suburban" 12 "Small Town/Rural", noticks) xtitle("Respondent Partisanship") ytitle("Mean Undocumented Immigrant Feeling Therm. Score") scheme(s2gcolor)

/////////// NOTE: once you have run the above, you will need to re-load the data






//////////////////////////////////////////////////////////////////////////////////
// APPENDIX FIGURES
///////////////////////////////////////////////////////////////////////////////////



/// A4 upper left

drop if check == 0

generate condimm = . 
replace condimm = 0 if urb_sub_o == 0 & kltexp==0
replace condimm = 1 if urb_sub_o == 0 & kltexp==1
replace condimm = 2 if urb_sub_o == 0 & kltexp == 2
replace condimm = 3 if urb_sub_o==0 & kltexp==3
replace condimm = 0 if urb_sub_o == 4
replace condimm = 5 if urb_sub_o == 1 & kltexp==0
replace condimm = 6 if urb_sub_o == 1 & kltexp==1
replace condimm = 7 if urb_sub_o == 1 & kltexp == 2
replace condimm = 8 if urb_sub_o==1 & kltexp==3
replace condimm = 0 if urb_sub_o == 9
replace condimm = 10 if urb_sub_o == 2 & kltexp==0
replace condimm = 11 if urb_sub_o == 2 & kltexp==1
replace condimm = 12 if urb_sub_o == 2 & kltexp == 2
replace condimm = 13 if urb_sub_o==2 & kltexp==3

graph bar (mean) expft_imm, over(kltexp) over(urb_sub_o) asyvars 


collapse (mean) meanimmexp= expft_imm (sd) sdftimm=expft_imm (count) n=expft_imm, by(kltexp urb_sub_o condimm)
generate hiimmft = meanimmexp + invttail(n-1,0.025)*(sdftimm/sqrt(n))
generate loimmft = meanimmexp - invttail(n-1,0.025)*(sdftimm/sqrt(n))
graph twoway (bar meanimmexp kltexp) (rcap hiimmft loimmft kltexp), by(urb_sub_o)
graph twoway (bar meanimmexp condimm if kltexp==0) (bar meanimmexp condimm if kltexp == 1) (bar meanimmexp condimm if kltexp==2) (bar meanimmexp condimm if kltexp==3) (rcap hiimmft loimmft condimm), legend (order(1 "Control" 2 "Economic Condition" 3 "Respect Condition" 4 "Majority-Minority Condition")) xlabel(0 "Urban" 6 "Suburban" 12 "Small Town/Rural", noticks) xtitle("Respondent Partisanship") ytitle("Mean Undocumented Immigrant Feeling Therm. Score") scheme(s2gcolor)


/////////// NOTE: once you have run the above, you will need to re-load the data




/// A4 lower left

drop if check == 0

generate condimm = . 
replace condimm = 0 if urb_sub_o == 0 & kltexp==0 & white==1
replace condimm = 1 if urb_sub_o == 0 & kltexp==1 & white==1
replace condimm = 2 if urb_sub_o == 0 & kltexp == 2 & white==1
replace condimm = 3 if urb_sub_o==0 & kltexp==3 & white==1
replace condimm = 0 if urb_sub_o == 4
replace condimm = 5 if urb_sub_o == 1 & kltexp==0 & white==1
replace condimm = 6 if urb_sub_o == 1 & kltexp==1 & white==1
replace condimm = 7 if urb_sub_o == 1 & kltexp == 2 & white==1
replace condimm = 8 if urb_sub_o==1 & kltexp==3 & white==1
replace condimm = 0 if urb_sub_o == 9
replace condimm = 10 if urb_sub_o == 2 & kltexp==0 & white==1
replace condimm = 11 if urb_sub_o == 2 & kltexp==1 & white==1
replace condimm = 12 if urb_sub_o == 2 & kltexp == 2 & white==1
replace condimm = 13 if urb_sub_o==2 & kltexp==3 & white==1

graph bar (mean) expft_imm, over(kltexp) over(urb_sub_o) asyvars 


collapse (mean) meanimmexp= expft_imm (sd) sdftimm=expft_imm (count) n=expft_imm, by(kltexp urb_sub_o condimm)
generate hiimmft = meanimmexp + invttail(n-1,0.025)*(sdftimm/sqrt(n))
generate loimmft = meanimmexp - invttail(n-1,0.025)*(sdftimm/sqrt(n))
graph twoway (bar meanimmexp kltexp) (rcap hiimmft loimmft kltexp), by(urb_sub_o)
graph twoway (bar meanimmexp condimm if kltexp==0) (bar meanimmexp condimm if kltexp == 1) (bar meanimmexp condimm if kltexp==2) (bar meanimmexp condimm if kltexp==3) (rcap hiimmft loimmft condimm), legend (order(1 "Control" 2 "Economic Condition" 3 "Respect Condition" 4 "Majority-Minority Condition")) xlabel(0 "Urban" 6 "Suburban" 12 "Small Town/Rural", noticks) xtitle("Respondent Partisanship") ytitle("Mean Undocumented Immigrant Feeling Therm. Score") scheme(s2gcolor)


/////////// NOTE: once you have run the above, you will need to re-load the data



/// A4 upper right

drop if check == 0

generate condimm = . 
replace condimm = 0 if urb_sub_o == 0 & kltexp==0 & white==1 & pid_7 < .5
replace condimm = 1 if urb_sub_o == 0 & kltexp==1 & white==1 & pid_7 < .5
replace condimm = 2 if urb_sub_o == 0 & kltexp == 2 & white==1 & pid_7 < .5
replace condimm = 3 if urb_sub_o==0 & kltexp==3 & white==1 & pid_7 < .5
replace condimm = 0 if urb_sub_o == 4
replace condimm = 5 if urb_sub_o == 1 & kltexp==0 & white==1 & pid_7 < .5
replace condimm = 6 if urb_sub_o == 1 & kltexp==1 & white==1 & pid_7 < .5
replace condimm = 7 if urb_sub_o == 1 & kltexp == 2 & white==1 & pid_7 < .5
replace condimm = 8 if urb_sub_o==1 & kltexp==3 & white==1 & pid_7 < .5
replace condimm = 0 if urb_sub_o == 9
replace condimm = 10 if urb_sub_o == 2 & kltexp==0 & white==1 & pid_7 < .5
replace condimm = 11 if urb_sub_o == 2 & kltexp==1 & white==1 & pid_7 < .5
replace condimm = 12 if urb_sub_o == 2 & kltexp == 2 & white==1 & pid_7 < .5
replace condimm = 13 if urb_sub_o==2 & kltexp==3 & white==1 & pid_7 < .5

graph bar (mean) expft_imm, over(kltexp) over(urb_sub_o) asyvars 


collapse (mean) meanimmexp= expft_imm (sd) sdftimm=expft_imm (count) n=expft_imm, by(kltexp urb_sub_o condimm)
generate hiimmft = meanimmexp + invttail(n-1,0.025)*(sdftimm/sqrt(n))
generate loimmft = meanimmexp - invttail(n-1,0.025)*(sdftimm/sqrt(n))
graph twoway (bar meanimmexp kltexp) (rcap hiimmft loimmft kltexp), by(urb_sub_o)
graph twoway (bar meanimmexp condimm if kltexp==0) (bar meanimmexp condimm if kltexp == 1) (bar meanimmexp condimm if kltexp==2) (bar meanimmexp condimm if kltexp==3) (rcap hiimmft loimmft condimm), legend (order(1 "Control" 2 "Economic Condition" 3 "Respect Condition" 4 "Majority-Minority Condition")) xlabel(0 "Urban" 6 "Suburban" 12 "Small Town/Rural", noticks) xtitle("Respondent Partisanship") ytitle("Mean Undocumented Immigrant Feeling Therm. Score") scheme(s2gcolor)


/////////// NOTE: once you have run the above, you will need to re-load the data







/// A4 lkower right

drop if check == 0


generate condimm = . 
replace condimm = 0 if urb_sub_o == 0 & kltexp==0 & white==1 & pid_7 > .5
replace condimm = 1 if urb_sub_o == 0 & kltexp==1 & white==1 & pid_7 > .5
replace condimm = 2 if urb_sub_o == 0 & kltexp == 2 & white==1 & pid_7 > .5
replace condimm = 3 if urb_sub_o==0 & kltexp==3 & white==1 & pid_7 > .5
replace condimm = 0 if urb_sub_o == 4
replace condimm = 5 if urb_sub_o == 1 & kltexp==0 & white==1 & pid_7 > .5
replace condimm = 6 if urb_sub_o == 1 & kltexp==1 & white==1 & pid_7 > .5
replace condimm = 7 if urb_sub_o == 1 & kltexp == 2 & white==1 & pid_7 > .5
replace condimm = 8 if urb_sub_o==1 & kltexp==3 & white==1 & pid_7 > .5
replace condimm = 0 if urb_sub_o == 9
replace condimm = 10 if urb_sub_o == 2 & kltexp==0 & white==1 & pid_7 > .5
replace condimm = 11 if urb_sub_o == 2 & kltexp==1 & white==1 & pid_7 > .5
replace condimm = 12 if urb_sub_o == 2 & kltexp == 2 & white==1 & pid_7 > .5
replace condimm = 13 if urb_sub_o==2 & kltexp==3 & white==1 & pid_7 > .5

graph bar (mean) expft_imm, over(kltexp) over(urb_sub_o) asyvars 


collapse (mean) meanimmexp= expft_imm (sd) sdftimm=expft_imm (count) n=expft_imm, by(kltexp urb_sub_o condimm)
generate hiimmft = meanimmexp + invttail(n-1,0.025)*(sdftimm/sqrt(n))
generate loimmft = meanimmexp - invttail(n-1,0.025)*(sdftimm/sqrt(n))
graph twoway (bar meanimmexp kltexp) (rcap hiimmft loimmft kltexp), by(urb_sub_o)
graph twoway (bar meanimmexp condimm if kltexp==0) (bar meanimmexp condimm if kltexp == 1) (bar meanimmexp condimm if kltexp==2) (bar meanimmexp condimm if kltexp==3) (rcap hiimmft loimmft condimm), legend (order(1 "Control" 2 "Economic Condition" 3 "Respect Condition" 4 "Majority-Minority Condition")) xlabel(0 "Urban" 6 "Suburban" 12 "Small Town/Rural", noticks) xtitle("Respondent Partisanship") ytitle("Mean Undocumented Immigrant Feeling Therm. Score") scheme(s2gcolor)


/////////// NOTE: once you have run the above, you will need to re-load the data




















/// A6 left

drop if check == 0


generate condimm = . 
replace condimm = 0 if urb_sub_o == 0 & kltexp==0
replace condimm = 1 if urb_sub_o == 0 & kltexp==1  
replace condimm = 2 if urb_sub_o == 0 & kltexp == 2 
replace condimm = 3 if urb_sub_o==0 & kltexp==3 
replace condimm = 0 if urb_sub_o == 4
replace condimm = 5 if urb_sub_o == 1 & kltexp==0 
replace condimm = 6 if urb_sub_o == 1 & kltexp==1 
replace condimm = 7 if urb_sub_o == 1 & kltexp == 2 
replace condimm = 8 if urb_sub_o==1 & kltexp==3 
replace condimm = 0 if urb_sub_o == 9
replace condimm = 10 if urb_sub_o == 2 & kltexp==0 
replace condimm = 11 if urb_sub_o == 2 & kltexp==1 
replace condimm = 12 if urb_sub_o == 2 & kltexp == 2 
replace condimm = 13 if urb_sub_o==2 & kltexp==3 

graph bar (mean) expft_dem, over(kltexp) over(urb_sub_o) asyvars 


collapse (mean) meandemexp= expft_dem (sd) sdftdem=expft_dem (count) n=expft_dem, by(kltexp urb_sub_o condimm)
generate hidemft = meandemexp + invttail(n-1,0.025)*(sdftdem/sqrt(n))
generate lodemft = meandemexp - invttail(n-1,0.025)*(sdftdem/sqrt(n))
graph twoway (bar meandemexp kltexp) (rcap hidemft lodemft kltexp), by(urb_sub_o)
graph twoway (bar meandemexp condimm if kltexp==0) (bar meandemexp condimm if kltexp == 1) (bar meandemexp condimm if kltexp==2) (bar meandemexp condimm if kltexp==3) (rcap hidemft lodemft condimm), legend (order(1 "Control" 2 "Economic Condition" 3 "Respect Condition" 4 "Majority-Minority Condition")) xlabel(0 "Urban" 6 "Suburban" 12 "Small Town/Rural", noticks) xtitle("Respondent Partisanship") ytitle("Mean Democrat Feeling Therm. Score") scheme(s2gcolor)


/////////// NOTE: once you have run the above, you will need to re-load the data




// A6 right
drop if check == 0


generate condimm = . 
replace condimm = 0 if urb_sub_o == 0 & kltexp==0
replace condimm = 1 if urb_sub_o == 0 & kltexp==1  
replace condimm = 2 if urb_sub_o == 0 & kltexp == 2 
replace condimm = 3 if urb_sub_o==0 & kltexp==3 
replace condimm = 0 if urb_sub_o == 4
replace condimm = 5 if urb_sub_o == 1 & kltexp==0 
replace condimm = 6 if urb_sub_o == 1 & kltexp==1 
replace condimm = 7 if urb_sub_o == 1 & kltexp == 2 
replace condimm = 8 if urb_sub_o==1 & kltexp==3 
replace condimm = 0 if urb_sub_o == 9
replace condimm = 10 if urb_sub_o == 2 & kltexp==0 
replace condimm = 11 if urb_sub_o == 2 & kltexp==1 
replace condimm = 12 if urb_sub_o == 2 & kltexp == 2 
replace condimm = 13 if urb_sub_o==2 & kltexp==3 

graph bar (mean) expft_rep, over(kltexp) over(urb_sub_o) asyvars 


collapse (mean) meanrepexp= expft_rep (sd) sdftrep=expft_rep (count) n=expft_rep, by(kltexp urb_sub_o condimm)
generate hirepft = meanrepexp + invttail(n-1,0.025)*(sdftrep/sqrt(n))
generate lorepft = meanrepexp - invttail(n-1,0.025)*(sdftrep/sqrt(n))
graph twoway (bar meanrepexp kltexp) (rcap hirepft lorepft kltexp), by(urb_sub_o)
graph twoway (bar meanrepexp condimm if kltexp==0) (bar meanrepexp condimm if kltexp == 1) (bar meanrepexp condimm if kltexp==2) (bar meanrepexp condimm if kltexp==3) (rcap hirepft lorepft condimm), legend (order(1 "Control" 2 "Economic Condition" 3 "Respect Condition" 4 "Majority-Minority Condition")) xlabel(0 "Urban" 6 "Suburban" 12 "Small Town/Rural", noticks) xtitle("Respondent Partisanship") ytitle("Mean repocrat Feeling Therm. Score") scheme(s2gcolor)


/////////// NOTE: once you have run the above, you will need to re-load the data









/// Table A2

gen piduse = .
replace piduse = 0 if pid_7 < .5
replace piduse = 1 if pid_7 == .5
replace piduse = 2 if pid_7 > .5
reg expft_imm i.kltexp if rursmall==1 & check == 1
reg expft_imm i.kltexp##i.white if rursmall==1 & check == 1
reg expft_imm i.kltexp##i.piduse if rursmall==1 & check == 1
reg expft_imm i.kltexp##i.piduse if rursmall==1 & white==1 & check == 1


